<template>
  <div class="register">
    <div>
      <span class="iconfont iconicon-test"></span>
    </div>
    <div class="news">
      <span class="iconfont iconnew"></span>
    </div>
    <Authinput
      placeholder="用户名 / 手机号码"
      errMsg="请输入正确用户名 / 手机号码"
      :rule="/^.{3,11}$/"
      type="text"
      @setValue="setusername"
    />
    <Authinput
      placeholder="昵称"
      errMsg="请输入正确昵称"
      :rule="/^.{3,8}$/"
      type="text"
      @setValue="setnickname"
    />
    <Authinput
      placeholder="密码"
      errMsg="请输入合法密码"
      :rule="/^\d{3,11}$/"
      type="password"
      @setValue="setpassword"
    />
    <Button value="注册" @click.native="register" />
    <Button value="点击登录" @click.native="$router.push('/login')" />
  </div>
</template>

<script>
import Authinput from "../components/Authinput";
import Button from "../components/Button";
import { register } from "./loginApi";
export default {
  components: {
    Authinput,
    Button,
  },
  data() {
    return {
      username: "",
      nickname: "",
      password: "",
    };
  },
  methods: {
    setusername(newVal) {
      this.username = newVal;
    },
    setnickname(newVal) {
      this.nickname = newVal;
    },
    setpassword(newVal) {
      this.password = newVal;
    },
    register() {
      // this.$axios({
      //   method: "post",
      //   data: {
      //     username: this.username,
      //     nickname: this.nickname,
      //     password: this.password,
      //   },
      //   url: "/register",
      // })
      const data = {
        username: this.username,
        nickname: this.nickname,
        password: this.password,
      };
      register(data)
        .then((res) => {
          console.log(res.data);
          if (res.data.message === "注册成功") {
            this.$toast.success("注册成功啦");
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
};
</script>

<style lang="less" scoped>
.register {
  width: 360 / 360 * 100vw;
  padding: 18 / 360 * 100vw;
  // padding-left: 15 / 360 * 100vw;
  // padding-right: 15 / 360 * 100vw;
  background-color: #f2f2f2;

  .iconicon-test {
    font-size: 27 / 360 * 100vw;
  }
  .news {
    // width: 100%;
    text-align: center;
    .iconnew {
      font-size: 126 / 360 * 100vw;
      color: #d81e06;
    }
  }
}
</style>